import * as echarts from "../../ec-canvas/echarts.js"; //这个是ec-canvas 目录下的 echarts.js
// 获取应用实例
const app = getApp()
let chart = null;
 
function setOption(chart) {
  var option = {
    legend: {
      // Try 'horizontal'
      orient: 'vertical',
      right: 10,
      top: 'center'
    },
    dataset: {
      source: [
        ['product', '2015', '2016', '2017'],
        ['Matcha Latte', 43.3, 85.8, 93.7],
        ['Milk Tea', 83.1, 73.4, 55.1],
        ['Cheese Cocoa', 86.4, 65.2, 82.5],
        ['Walnut Brownie', 72.4, 53.9, 39.1]
      ]
    },
    xAxis: {
      type: 'category'
    },
    yAxis: {},
    series: [{
      type: 'bar'
    }, {
      type: 'bar'
    }, {
      type: 'bar'
    }]
  }
  chart.setOption(option);
  return chart;
}
Component({
  data: {
    ec: {
      lazyLoad: true,
    },
  },
  ready() {
    this.initpie();
  },
  methods: {
    initpie: function () {
      var query = wx.createSelectorQuery();
      query.select('#mychart-dom-bar').boundingClientRect(data => {
        console.log(data); // 在控制台打印元素的信息
      }).exec();
      // let ecComponent = this.selectComponent('#mychart-dom-bar');
      // ecComponent.init((canvas, width, height, dpr) => {
      //   // 获取组件的 canvas、width、height 后的回调函数
      //   // 在这里初始化图表
      //   chart = echarts.init(canvas, null, {
      //     width: width,
      //     height: height,
      //     devicePixelRatio: dpr // new
      //   });
      //   setOption(chart);
      //   return chart;
      // });
    },
  },
});